using System;
using System.Collections.Generic;
using System.Linq;
using bbv.DomainDrivenDesign.Interfaces;
using O1.Social.Newsgator.Data;
using O1.Social.Newsgator.Domain.Interfaces;

namespace O1.Social.Newsgator.Repository.LinqToSql
{
    public class ActivityEventRepository : Repository<ActivityEvent, IActivityEvent, int>, IActivityEventRepository
    {
        public ActivityEventRepository():this(new ActivityEventConverter())
        {            
        }

        public ActivityEventRepository(IConverter<IActivityEvent, ActivityEvent> converter) : base(converter) {}
        public ActivityEventRepository(IWorkspaceProvider workspaceCreator, IConverter<IActivityEvent, ActivityEvent> converter) : base(workspaceCreator, converter) {}

        #region Implementation of IActivityEventRepository

        public IList<IActivityEvent> GetFromDate(DateTime date)
        {
            using (var context = GetWorkspace())
            {
                return
                    context.CreateQuery<ActivityEvent>()
                           .Where(ae => ae.Date >= date)
                           .Select(Converter.Convert).ToList();
            }
        }

        #endregion
    }

    
}